package com.example.leetdemo.finash;

import java.util.Arrays;

public class Solution3218 {


    public static int minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
        int dp[][] = new int[m][n];
        for (int i = 1; i < m; i++) {
            dp[i][0] = dp[i - 1][0] + horizontalCut[i - 1];
        }
        for (int i = 1; i < n; i++) {
            dp[0][i] = dp[0][i - 1] +verticalCut[i - 1];
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                int h = horizontalCut[i - 1];
                int v = verticalCut[j - 1];
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + Math.min(h , v) - dp[i - 1][j - 1];
            }
        }
        return dp[m - 1][n - 1];
    }

    public static void main(String[] args) {
        System.err.println(minimumCost(3, 2, new int[]{1, 3}, new int[] {5}));
    }

}
